<?php

namespace app\admin\model;

use think\Model;

class LoginLogModel extends Model
{
    protected $table = 'login_logs';

    protected $hidden = [];

    protected $autoWriteTimestamp = true;

    public static function lists($request)
    {
        $lists = LoginLogModel::order('id desc');
        if (!isset($request['page']) || empty($request['page'])) {
            $request['page'] = "1";
        }
        if (!isset($request['limit']) || empty($request['limit'])) {
            $request['limit'] = "10";
        }
        if (isset($request['username']) && $request['username'] != '') {
            $lists = $lists->where("username", "like", "%" . $request['username'] . "%");
        }
        if (isset($request['status']) && $request['status'] != '') {
            $lists = $lists->where("status", $request['status']);
        }
        $data['count'] = $lists->count();
        $data['lists'] = $lists->limit(($request['page'] - 1) * $request['limit'], $request['limit'])->select();
        return baseResponse(0, '获取登录列表成功', $data);
    }

    public static function addLog($username, $type, $password, $ip, $status)
    {
        LoginLogModel::create(compact('username', 'type', 'password', 'ip', 'status'));
    }

}
